<?php  
$pPageIsPublic = false;
include '../_common.php';
	
$pTitle  = 'New Image';
$pButton = 'Save';
$action  = 'add';
$id 	 = intval($_REQUEST['id']);
$bid 	 = intval($_REQUEST['bid']);
$seo	 = NULL;

if (!$bid)
	Tzn::redirect('building-add.php', 'Create a building.'); 

$objMedia = new File();
$objMedia ->setUid($id);
if ($objMedia ->load()) {
	$pTitle  = 'Edit Image';
	$pButton = 'Update';
	$action  = 'edit';
	
	if ($_GET['remove']) {
		$objMedia ->removeFile();
		$message = "Image has been removed.";  
	}
}


$_SESSION["m1"]	= "content";
$_SESSION["m2"] = ($bid == 2 ? "page" :  "building"). "-list";
$url = $bid == 2 ? "contact-page.php?tab=images" : "building-add.php?tab=images";


if (isset($_POST['submit'])) {

	$objMedia ->setAuto($_POST);
	$objMedia ->uploadFile();
	$objMedia ->page ->id = $bid; 
	if ($_POST['action'] == 'edit') {
		$objMedia ->getConnection();
		$objMedia ->setUid($id);
		$objMedia ->update();
		Tzn::redirect("{$url}&id=". $bid, "Image has been updated.");
	} elseif ($_POST['action'] == 'add') {
		$objMedia ->add();
		Tzn::redirect("$url&id=". $bid, "Image has been added.");
	}
}
?>
<?php include("header.php"); ?>
<script type="text/javascript">
$(document).ready(function(){
	$('#frmMain').validate();	
});
</script>
<?php include("sidebar.php"); ?>
<ul id="subnav" >
	<li ><a class="back" href="<?="{$url}&id={$bid}"; ?>" > Back </a></li>
	<li class="noborder" >
		<a class="add" href="<?="image-add.php?bid=$bid"?>"> Add a New Image </a>
	</li>
</ul>
<div id="list">
<h2> <?php echo $pTitle;?> </h2>  
<form action="" method="post" name = "frmMain" id = "frmMain" enctype="multipart/form-data" >
<fieldset><legend> General Info </legend>
	<table cellpadding="0" cellspacing="0" class="table-form"  >
		<tr>
			<th>Title: </th>
					<td><?php $objMedia ->qText('title', '', 'width:548px', 'class="required"');?></td>
				</tr>
				<tr>
				<th>Image: </th>
					<td><?php $objMedia ->pFile('ifile', "{$_SERVER['PHP_SELF']}?bid=$bid&id=$id&remove=1" ) ?></td>
				</tr>
<?php
	if ($bid==2) { 
?>	
			<tr>
				<th>Phono: </th>
				<td><?php $objMedia ->qText('var1', '', 'width:200px', 'class="required"');?></td>
			</tr>
			<tr>
				<th>Email: </th>
				<td><?php $objMedia ->qText('var2', '', 'width:200px', 'class="required email"');?></td>
			</tr>

<?php
	} 
?>
				<tr>
					<th>Status: </th>
					<td><?php $objMedia ->arrayToSelect($objMedia ->_arrStatus, 'status', $objMedia ->status, false, 'width:100px', '');?></td>
				</tr>
			</table>
	</fieldset>
	<div style="margin-top:10px">
		<input type="hidden" name="id" value="<?php echo $id; ?>" />
		<input type="hidden" name="bid" value="<?php echo $bid; ?>" />
		<input type="hidden" name="action" value="<?php echo $action; ?>" />
                <input type="submit" name="submit"  value="<?php echo $pButton; ?>" /> &nbsp; <input type="reset" value="Cancel" onClick="window.location.href='<?="{$url}&id=$bid"; ?>'" />
            </div>
            </form>
</div>
<?php include("footer.php"); ?>